const XML = require('../utils/ObjTree');
const ObjTree = new XML.ObjTree();
const request = require("request");
const xml2js = require('xml2js');

const getRoute = () => {
  return new Promise((resolve, reject) => {
    request({
      headers: { "Connection": "close" },
      url: 'https://secure.shippingapis.com/ShippingAPI.dll?API=TrackV2&XML=<TrackRequest USERID="597CHINA3162"><TrackID ID="9300169903503193306666"></TrackID><TrackID ID="9300169903503195397754"></TrackID></TrackRequest>',
      method: 'GET',
    }, (error, response, data) => {
      if (!error && response.statusCode == 200) {
        // console.log('------接口数据------', data);
        xml2js.parseString(data, {
          attrkey: "@", attrValueProcessors: [function (val, name) {
            console.log('val', val)
            console.log('name', name)
            return name
          }]
        }, function (err, result) {
          resolve(result)
        });
      }
    })
  })
}

module.exports = {
  getRoute
}